package com.barrett.hvzmoderator.com.barrett;

import com.barrett.hvzmoderator.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class hvzedit extends Activity {
	int tags;
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit);
        
        final int uid = getIntent().getIntExtra("uid",0);
        String name = getIntent().getStringExtra("name");
        String killid = getIntent().getStringExtra("killid");
        int status = getIntent().getIntExtra("status", 0);
        tags = getIntent().getIntExtra("tags", 0);
        
        final EditText nameText = (EditText) findViewById(R.id.edit_name);
        nameText.setText(name);
        final EditText killidText = (EditText) findViewById(R.id.edit_killid);
        killidText.setText(killid);
        final EditText tagsText = (EditText) findViewById(R.id.edit_tags);
        tagsText.setText(Integer.toString(tags));
        final Spinner statusSpinner = (Spinner) findViewById(R.id.edit_status_spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.Stati, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        statusSpinner.setAdapter(adapter);
        statusSpinner.setSelection(status - 1);
        
        
        Button back = (Button) findViewById(R.id.edit_back);
        Button save = (Button) findViewById(R.id.edit_save);
        
        
        
        back.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				Intent intentBack = new Intent();
	            setResult(RESULT_OK, intentBack);
	            finish();
				
			}
		});
        save.setOnClickListener(new View.OnClickListener() {
			
        	
        	
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				hvzplayer player = new hvzplayer(uid + ","
						+nameText.getText() + ","
						+killidText.getText() + ","
						+(statusSpinner.getSelectedItemPosition() + 1) + ","
						+tagsText.getText());
				Intent intentSave = new Intent();
				intentSave.putExtra("player", player.toString());
				setResult(1, intentSave);
				finish();
			}
		});
	}

}
